package DAO.Impl;

import DAO.beginnerDAO;
import domain.beginner;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * @description: 数据库连接操作层实现类
 * @author: hank
 * @create: 2021-03-28 21:25
 **/
@SuppressWarnings("JavaDoc")
public class beginnerDAOImpl implements beginnerDAO{
    private final Connection conn;
    private PreparedStatement pstmt;

    public beginnerDAOImpl(Connection conn) {
        this.conn = conn;
    }

    @Override
    public List<beginner> getBeginner() throws SQLException {
        String sql="SELECT * FROM beginner LIMIT 8";
        this.pstmt = conn.prepareStatement(sql);
        ResultSet rs = this.pstmt.executeQuery();
        List<beginner> all = new ArrayList<beginner>();
        while (rs.next()) {
            beginner vo = new beginner();
            vo.setID(rs.getInt(1));
            vo.setName(rs.getString(2));
            all.add(vo);
        }
        return all;
    }
}
